package com.miaowang.salad.jobqueue;

import com.alibaba.fastjson.JSON;
import com.miaowang.salad.data.OkHttpResponseData;
import com.miaowang.salad.net.OkHttpUtils;
import com.miaowang.salad.net.UrlUtils;
import com.path.android.jobqueue.Job;
import com.path.android.jobqueue.Params;

import de.greenrobot.event.EventBus;

/**
 * 取消服务20151027
 * @author Administrator
 *
 */
public class CancelServiceRequestJob extends Job {
	
	private String serviceType = "";

	public CancelServiceRequestJob(String serviceType) {
		super(new Params(JobQueuePriority.PRIORITY_HIGH).groupBy(JobQueuePriority.JOBS_GROUP_USER).requireNetwork());
		this.serviceType = serviceType;
	}

	@Override
	public void onAdded() {

	}

	@Override
	protected void onCancel() {

	}

	@Override
	public void onRun() throws Throwable {
		 String result = OkHttpUtils.post(UrlUtils.CANCEL_SERVICE_REQUESTS,"");
//         String result = OkHttpUtils.post(UrlUtils.SEND_SERVICE_REQUESTS, "service_type",serviceType);
         OkHttpResponseData responseData = JSON.parseObject(result, OkHttpResponseData.class);
         EventBus.getDefault().post(new JobEvents.JobSuccess<>(JobEvents.CANCEL_SERVICE_REQUESTS,responseData));
	}

//	@Override
//	protected RetryConstraint shouldReRunOnThrowable(Throwable throwable,
//			int runCount, int maxRunCount) {
//		EventBus.getDefault().post(new JobEvents.JobFailure(JobEvents.SEND_SERVICE_REQUESTS));
//		return super.shouldReRunOnThrowable(throwable, 1, 3);
//	}
	
	@Override
	protected boolean shouldReRunOnThrowable(Throwable throwable) {
		EventBus.getDefault().post(new JobEvents.JobFailure(JobEvents.CANCEL_SERVICE_REQUESTS));
		return false;
	}
	
	
	
	

}
